<%-- Copyright (c) 2002 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<script language="javascript" src="<%=request.getContextPath()%>/mc/js/date.js"></script>

<SCRIPT>
function checkMaxLength(taText,len)
{
    if (taText.value.length > len)
        taText.blur();
}

function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
}

// function to do POST of form paramters to a ".do"
function doAction(action, myform){
    myform.action='<html:rewrite page="'+action+'" />';
    myform.submit();
    return true;
}

// function to validate the form contents before doing a POST operation.
function validateForm(myform)
{
    if( validate(myform) == false)
      return false;

    var val;
    for (i=0;i<myform.defaultAction.length;i++)
    {
    	if (myform.defaultAction[i].checked)
    	{
    	   val = myform.defaultAction[i].value;
    	}
    }
    if( val == "1" && myform.itemKey.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectItem" /> ");
          return false;
    }

    if( val == "2" && myform.categoryPath.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectCategory" /> ");
          return false;
    }
    return true;
}


function onSelectContent( selectedOids, selectedNames) {
  theForm = document.emRuleSetForm;
  theForm.itemKey.value = selectedNames.toString();
  theForm.contentOid.value = parseInt(selectedOids.toString());
}

function onSelectCategory( selectedOids, selectedNames) {
  theForm = document.emRuleSetForm;
  theForm.categoryPath.value = selectedNames.toString();
  theForm.categoryOid.value = parseInt(selectedOids.toString());
}

function onClickDoNothing( form ) {

  form.browseItem.disabled=true;
  form.browseCategory.disabled=true;
  form.includeSubCategory.disabled=true;
  form.numItems.disabled=true;

  form.itemKey.value="";
  form.categoryPath.value="";
  form.numItems.value="1";
  form.includeSubCategory.checked=false;
}

function onClickItemAction( form ) {

  form.browseItem.disabled=false;

  form.browseCategory.disabled=true;

  form.numItems.disabled=true;
  form.numItems.value="1";

  form.includeSubCategory.disabled=true;
  form.includeSubCategory.checked=false;

  form.categoryPath.value="";

}

function onClickCategoryAction( form ) {

  form.browseItem.disabled=true;

  form.browseCategory.disabled=false;
  form.includeSubCategory.disabled=false;
  form.numItems.disabled=false;

  form.itemKey.value="";
}

</SCRIPT>

<html:javascript formName="emRuleSetForm" method="validate" />

<table width="100%" border="0" cellspacing="0" cellpadding="0"
	class="zoneFive">
	<tr>
		<td valign="top" width="100%">
		<div class="pageTitle">
	      <bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryEdit.pageTitle"/>:
		<bean:write name="emRuleSetForm" property="name"/>
		</div>
		<div class="errorMessage"><html:errors bundle="em"/></div>
    		<div><%@include file="/mc/common/pagetab.jsp"%></div>

        <div class="pageInstructions">
             <bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryEdit.pageInstruction"/>
        </div>

        <div class="pageSubtitle">
             <bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryEdit.header"/>
        </div>

        <html:form action="/em/ruleset/ruleSetUpdate.do" focus="name" onsubmit="return validateForm(this);">
	    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="labelForm">
            <html:hidden name="emRuleSetForm" property="oid" />
		<tr>
                <td valign="top" nowrap class="label" width="30%">
			<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.lable.ruleSetName"/>*:
		    </td>
                <td valign="top" nowrap class="labelField" width="70%">
		   <html:messages id="nameError" property="name" bundle="em" />
		   <c:if test="${not empty nameError}">
			<span class="errorMessage">
				<c:out value="${nameError}" />
			</span>
		    <br>
            	   </c:if>
                    <html:text name="emRuleSetForm" property="name" size="30" maxlength="80"/>
                </td>
            </tr>
            <tr>
                <td valign="top" nowrap class="label" width="30%">
			<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummary.lable.offerContentType"/>*:
		    </td>
                <td valign="top" wrap class="labelField" width="70%">
                    <bean:write name="emRuleSetForm" property="contentTypeName"/>
                    <html:hidden name="emRuleSetForm" property="contentType" />
                </td>
            </tr>
            <tr>
                <td valign="top" nowrap class="label" width="30%">
                    <bean:message bundle="em" key="emarketing.ruleset.text.description"/>:
                </td>
                <td valign="top" nowrap class="labelField" width="70%">
		    <html:messages id="descriptionError" property="description" bundle="em" />
		    <c:if test="${not empty descriptionError}">
			<span class="errorMessage">
			       <c:out value="${descriptionError}" />
			</span>
		    <br>
            	    </c:if>
                    <html:textarea name="emRuleSetForm" property="description" onkeypress="checkMaxLength(this,255)" rows="3" cols="40"/>
                </td>
		</tr>
		<tr>
		<td valign="top" wrap class="label" width="30%">
                	<bean:message bundle="em" key="em.label.status"/>:
            	</td>
		<td valign="top" nowrap class="labelField" width="70%">
		    	<html:radio name="emRuleSetForm" property="status" value="1"/>
		    	<bean:message bundle="em" key="em.label.online"/>
		    	<html:radio name="emRuleSetForm" property="status" value="0"/>
		    	<bean:message bundle="em" key="em.label.offline"/>
		</td>
	     </tr>
	     <tr>
		<td valign="top" wrap class="label" width="30%">
                	<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluationMethod"/>:*
            	</td>
			<td valign="top" nowrap class="labelField" width="70%">
		   	<html:select property="evalMethod" >
			<logic:equal name="emRuleSetForm" property="evalMethod" value="ALL">
				<option value="ALL" selected="selected">
			</logic:equal>
			<logic:notEqual name="emRuleSetForm" property="evalMethod" value="ALL">
				<option value="ALL">
			</logic:notEqual>
			<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluateall"/>
			</option>
			<logic:equal name="emRuleSetForm" property="evalMethod" value="FIRST">
				<option value="FIRST" selected="selected">
			</logic:equal>
			<logic:notEqual name="emRuleSetForm" property="evalMethod" value="FIRST">
				<option value="FIRST">
			</logic:notEqual>
			<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluatefirst"/>					      </option>
		   	</html:select>
            	</td>
	      </tr>
		<tr>
                <td valign="top" nowrap class="label" width="30%">
                      <bean:message bundle="em" key="emarketing.ruleset.text.lastModified"/>:
                </td>
                <td valign="top" nowrap class="labelField" width="70%">

                    <bean:write name="emRuleSetForm" property="lastModifiedDate" bundle="em"  formatKey="format.datetime.long"/>
                </td>
        	</tr>
                <tr>
                  <td valign="top" nowrap class="label" width="30%">
		    <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.header.defaultAction" />*:
	          </td>
	          <td valign="top" nowrap class="labelField" width="70%">
				<html:radio name="emRuleSetForm" property="defaultAction" value="0" onclick="onClickDoNothing(this.form) "/>
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.doNothing" />
				</td>
		</tr>
		<tr>
		  <td valign="top" nowrap class="label" width="30%">&nbsp;</td>
		  <td valign="top" nowrap class="labelField" width="70%">
				<html:radio name="emRuleSetForm" property="defaultAction" value="1" onclick="onClickItemAction(this.form)" />
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickOneItem" />
			</td>
		</tr>
		<tr>
		  <td valign="top" nowrap class="label" width="30%">&nbsp;</td>
		  <td valign="top" nowrap class="labelField" width="70%">
				<html:text name="emRuleSetForm" size="30" property="itemKey" disabled="true" />
				<logic:equal name="emRuleSetForm" property="defaultAction" value="1" >
					<input type="button" name="browseItem"
						value="<bean:message bundle="em" key="button.browseItem"/>"
						class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/pickerPopup.do"/>', 'onSelectContent', this.form.contentType.value, null, null, null, true, false, true);" />
				</logic:equal>
				<logic:notEqual name="emRuleSetForm" property="defaultAction" value="1" >
					<input type="button" name="browseItem"
						value="<bean:message bundle="em" key="button.browseItem"/>"
						class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/pickerPopup.do"/>', 'onSelectContent', this.form.contentType.value, null, null, null, true, false, true);" disabled="true"/>
				</logic:notEqual>

			</td>
			<html:hidden name="emRuleSetForm" property="contentOid"/>
		</tr>
		<tr>
		  <td valign="top" nowrap class="label" width="30%">&nbsp;</td>
		  <td valign="top" nowrap class="labelField" width="70%">
				<html:radio name="emRuleSetForm" property="defaultAction" value="2" onclick="onClickCategoryAction(this.form)" />
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickCategory" />
		  </td>
		</tr>
		<tr>
		  <td valign="top" nowrap class="label" width="30%">&nbsp;</td>
		  <td valign="top" nowrap class="labelField" width="70%">

				<html:text name="emRuleSetForm" size="30" property="categoryPath" disabled="true"/>
				<logic:equal name="emRuleSetForm" property="defaultAction" value="2" >
					<input type="button" name="browseCategory"
						value="<bean:message bundle="em" key="button.browseCategory"/>"
						class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/categoryPickerPopup.do"/>', 'onSelectCategory', this.form.contentType.value, null, null, null, true, false, false );" />
					<br>
					<bean:message bundle="em" key="emarketing.ruleset.text.numContents" />*:
					<html:text name="emRuleSetForm" size="3" maxlength="3" property="numItems" onkeypress="return checkNumberOnly(event)"/>
					<br>
					<html:checkbox name="emRuleSetForm" property="includeSubCategory" />
					<bean:message bundle="em" key="emarketing.ruleset.text.includeSubCategories" />
				</logic:equal>
				<logic:notEqual name="emRuleSetForm" property="defaultAction" value="2" >
					<input type="button" name="browseCategory"
						value="<bean:message bundle="em" key="button.browseCategory"/>"
						class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/categoryPickerPopup.do"/>', 'onSelectCategory', this.form.contentType.value, null, null, null, true, false, false );" disabled="true" />
					<br>
					<bean:message bundle="em" key="emarketing.ruleset.text.numContents" />*:
					<html:text name="emRuleSetForm" size="3" maxlength="3" property="numItems" disabled="true" onkeypress="return checkNumberOnly(event)"/>
					<br>
					<html:checkbox name="emRuleSetForm" property="includeSubCategory" disabled="true"/>
					<bean:message bundle="em" key="emarketing.ruleset.text.includeSubCategories"/>
				</logic:notEqual>

			<br>
				<html:messages id="numItemsError" property="numItems" bundle="em" />
				<c:if test="${not empty numItemsError}">
					<span class="errorMessage">
						<c:out value="${numItemsError}" />
					</span>
            			</c:if>
			        <html:hidden property="categoryOid"/>
			</td>
		</tr>
	</table>

    	<div class="pageButtonWrap" align="right">
		  <input type="button"    name="resetButton"
                          class="inputButton"
                          value="<bean:message bundle="em" key="button.reset"/>"
                          onClick="doAction('/em/ruleset/ruleSetEdit.do', this.form);">
                  &nbsp;&nbsp;
	          <input type="button" name="cancelButton"
                      class="inputButton"
                      value="<bean:message bundle="em" key="button.cancel"/>"
                      onClick="doAction('/em/ruleset/ruleSetView.do', this.form);"/>

          	    <input type="submit" name="saveButton"
                      class="inputButton"
                      value="<bean:message bundle="em" key="button.save"/>" />
    	</div>
  	</html:form>
  	</td>
  </tr>
  </table>
